//index.js
const app = getApp()

Page({
  data: {
    list: [{
        src: "https://sd.offcn.com/zg/wximg/2021/zsb/tslq-img/book1.png",
        text: "专升本-备考宝典"
      },
      {
        src: "https://sd.offcn.com/zg/wximg/2021/zsb/tslq-img/book2.png",
        text: "专升本-英语必背词汇"
      }
    ],
  },


  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }
  },
  getPhoneNumber(e) {
    var that = this;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      that.setData({
        mobile: res.result,
      })
      wx.setStorageSync('phone', res.result)
      console.log(res.result)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/biaodan/register?actid=40453&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: that.data.area,
          geneal: that.data.geneal,
          isagree:true,
          userid: that.data.geneal
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          wx.redirectTo({
            url: '../tslq_res/tslq_res',
          })
        }
      })
      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId:34,
          mobile: res.result,
          areaCode: that.data.area,
          agent: that.data.geneal,
          pageId: that.data.page
        },
        success: res => {
          console.log(res);
        }
      })

    }).catch(err => {
      console.error(err);
    });
  },



  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '2022山东专升本考试图书领取',
      path: 'pages/tslq/tslq'
    }
  },
  /**分享到朋友圈*/
  onShareTimeline: function () {
    return {
      title: '2022山东专升本考试图书领取',
      path: 'pages/tslq/tslq'
    }
  }
})